--[[
  江西银行 核心接口 - 8000端口和8888端口
]]
require("apm_core")

local G_DEBUG = true

if G_DEBUG == false then
    function logDebug(fmt, ...) end
    function logInfo(fmt, ...) end
    function logWarn(fmt, ...) end
    function logError(fmt, ...) end
    function logFatal(fmt, ...) end
end

local KRED = '\x1B[0;31m'
local KSALMON = '\x1B[1;31m'
local KGREEN = '\x1B[0;32m'
local KLIMEGREEN = '\x1B[1;32m'
local KYELLOW = '\x1B[0;33m'
local KORANGE = '\x1B[0;34m'
local KBLUE = '\x1B[1;34m'
local KMAGENTA = '\x1B[0;35m'
local KPINK = '\x1B[1;35m'
local KCYAN = '\x1B[0;36m'
local RESET = '\x1B[0m'

local dict_channelname = {
    ["EUB"] = "VTM",
    ["ATM"] = "本行ATM",
    ["BCK"] = "后台",
    ["CAL"] = "电话人工",
    ["CDS"] = "自助取款机",
    ["CPR"] = "合作方",
    ["CUA"] = "中国银联ATM",
    ["CUP"] = "中国银联POS",
    ["DSK"] = "柜面",
    ["INT"] = "个人网上银行",
    ["PAY"] = "电子支付",
    ["POS"] = "本行POS",
    ["STM"] = "自助终端",
    ["TEL"] = "电话语音",
    ["MPH"] = "手机银行",
}

function post_analysis()
    local ApmData = require("ApmData")

    local s_channelcode
    local s_channelname
    local s_flowno

    -- 渠道类型
    s_channelcode = ApmData.getField("transaction.channel_code", 1)
    if s_channelcode ~= nil and s_channelcode ~= "" then
        s_channelname = dict_channelname[s_channelcode]
        if s_channelname == nil then s_channelname = s_channelcode end

        ApmData.replaceField("transaction.channel_code", s_channelcode)
        ApmData.replaceField("transaction.channel_name", s_channelname)
    end

    if ApmData.getMsgType() ~= 1 then return end

    -- 交易号
    s_flowno = ApmData.getField("transaction.code", 1)
    if s_flowno ~= nil and s_flowno == "00000000000000000000" then
        s_flowno = ApmData.getField("response.jxbankc.gsrsproot.ComReq", 1)
        if s_flowno ~= nil and s_flowno ~= "00000000000000000000" then
            ApmData.replaceField("transaction.code", s_flowno)
        end
    end

    return
end

--核心接口
--10.1.1.124:8000
--10.1.1.125:8000
--10.1.1.126:8000
--10.1.16.50:8888
--v1.0.1
